<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>获取图片的宽高</title>
</head>

<body>

</body>
<script>
  "use strcit"; {
    let img_url = 'http://www.qttc.net/static/upload/2013/13643608813441.jpg';
    // 创建对象
    let img = new Image();
    // 改变图片的src
    img.src = img_url;
    // 判断是否有缓存
    if (img.complete) {
      // 打印
      console.log(`from:complete: width: ${img.width} ,height: ${img.height}`);
      alert();
    } else {
      // 加载完成执行
      img.onload = () => {
        // 打印
        console.log(`from:onload: width: ${img.width} ,height: ${img.height}`);
      };
    };
  };
</script>

</html>